import { sendSms, sendGroupSms } from '@/services/excel';
import { errNotification, successNotification } from '@/utils/notification';

export default {
    namespace: 'smsImport',
  
    state: {
      isShow: false,
      smsList: [],
      isGroupShow: false,
      smsGroup: {}
    },
  
    effects: {
      *fetchSendSms(param, { call, put }) {
        const response = yield call(sendSms, param);
        if(response.success){
          successNotification("提交成功","")
          yield put({
            type: 'setShow',
            payload: {
              list: [],
              isShow: false
            }
          });
        }else{
          errNotification("提交失败", response.subMsg)
        }
      },
      *fetchSendGroupSms(param, { call, put }) {
        const response = yield call(sendGroupSms, param);
        if(response.success){
          successNotification("提交成功","")
          yield put({
            type: 'setGroupShow',
            payload: {
              isGroupShow: false,
              smsGroup: {}
            }
          });
        }else{
          errNotification("提交失败", response.subMsg)
        }
      },
    },
  
    reducers: {
      setShow(state, action) {
        if(action.payload.list){
            action.payload.list.map((item,index)=>{
              item.key = index
            })
        }
        return {
          ...state,
          isShow: action.payload.isShow,
          smsList: action.payload.list
        };
      },
      setGroupShow(state, action) {
        return {
          ...state,
          isGroupShow: action.payload.isGroupShow,
          smsGroup: action.payload.smsGroup
        };
      },
    },
  };